<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- 避免IE使用兼容模式 -->
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
<meta name="renderer" content="webkit">
<!-- TopJUI框架样式 -->
<link type="text/css" href="../../topjui/themes/default/topjui.core.min.css" rel="stylesheet">
<link type="text/css" href="../../topjui/themes/default/topjui.blue.css" rel="stylesheet" id="dynamicTheme" />
<!-- FontAwesome字体图标 -->
<link type="text/css" href="../../statics/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" />
<!-- layui框架样式 -->
<link type="text/css" href="../../statics/plugins/layui/css/layui.css" 	rel="stylesheet" />
<!-- jQuery相关引用 -->
<script type="text/javascript" src="../../statics/plugins/jquery/jquery.min.js"></script>
<script type="text/javascript" src="../../statics/plugins/jquery/jquery.cookie.js"></script>
<!-- TopJUI框架配置 -->
<script type="text/javascript" src="../../statics/public/js/topjui.config.js"></script>
<!-- TopJUI框架核心-->
<script type="text/javascript" src="../../topjui/js/topjui.core.min1.js"></script>
<!-- TopJUI中文支持 -->
<script type="text/javascript" src="../../topjui/js/locale/topjui.lang.zh_CN.js"></script>
<!-- layui框架js -->
<script type="text/javascript" src="../../statics/plugins/layui/layui.js" charset="utf-8"></script>
<script>
//var CHKPOINTID='';
</script>
</head>
<body>
	<div data-toggle="topjui-layout" data-options="fit:true">
		<div
			data-options="region:'center',title:'',fit:true,split:true,border:false">
			<!-- datagrid表格 -->
			<table data-toggle="topjui-datagrid" class="productDg1"
				data-options="id: 'chkpointDg',
               				fitColumns:true,
              				remoteSort:false,
               				method:'get',
               				url: '/chkpoint/queryChkpoint'">
				<thead>
					<tr>
						<th data-options="field:'chkpointname',title:'巡查地点',sortable:true,width:80,align:'center'"></th>
						<th data-options="field:'name',title:'负责人',sortable:true,width:50,align:'center'"></th>
						<th data-options="field:'timesineveryday',title:'每日巡查次数',sortable:true,width:70,align:'center'"></th>
						<th data-options="field:'chkpointdes',title:'位置描述',sortable:true,width:150"></th>
						<th data-options="field:'chkcontent',title:'巡查任务描述',sortable:true,width:150"></th>
						<th data-options="field:'operate',title:'操作',formatter:operateFormatter,width:100,align:'center'"></th> 	
					</tr>
				</thead>
			</table>
		</div>
	</div>
	<!-- layout布局 结束 -->

	<!-- 表格工具栏开始 -->
	<div id="chkpointDg-toolbar" class="topjui-toolbar"
		data-options="grid:{
           type:'datagrid',
           id:'chkpointDg'
       }">
       <a href="javascript:void(0)" data-toggle="topjui-menubutton"
			data-options="iconCls: 'fa fa-plus',btnCls:'topjui-btn-blue'" onclick="openAddDiag()">新增</a>
		<form id="queryForm" class="search-box">
		
			<input type="text" name="chkpointname" data-toggle="topjui-textbox"
				data-options="id:'chkpointname',prompt:'巡查地点',width:150,validType:'maxLength[30]'">
                      	
			<a href="javascript:void(0)" data-toggle="topjui-menubutton"
				data-options="method:'query',
           					iconCls:'fa fa-search',
           					btnCls:'topjui-btn-blue',
           					form:{id:'queryForm'},
           					grid:{type:'datagrid','id':'chkpointDg'}">查询</a>
		</form>
	</div>
	<!-- 表格工具栏结束 -->
	<script>
	function openAddDiag(){
		ID = '';
		var $addDialog = $('<form id="chkpointDg-add"  style="width: 900px; height:500px; margin: auto; display: none;"></form>');
		var diag = $addDialog.dialog({
		    title: '巡查点新建',
		    href: '/web/view/chk/chkpoint_add.html',
		    modal: true,
		    resizable:true,
 		    maximizable:true,
		    collapsible:true,
		    buttons:[{
				text:'保存',
				handler:function(){
					if($('#chkpointDg-add').form('validate')) {
						var formData = $("#chkpointDg-add").serialize();
						var url = '/chkpoint/insertChkpoint';
			            $.post(url,formData+'&chkpointid='+ID,function (res,status) {
			                if (status == 'success') { // 后台返回状态值
			                    $.iMessager.show({title: '我的消息', msg: res.message, timeout: 5000, showType: 'slide'});// '消息窗口'组件
			                    $("#chkpointDg").iDatagrid('reload');// 刷新下表格数据
			                    diag.dialog("destroy");// 销毁dialog面板
			                } else {
			                    $.iMessager.show({title: '我的消息', msg: res.message, timeout: 5000, showType: 'slide'});// '消息窗口'组件
			                }
			            },'JSON');
					}
				}
			},{
				text:'关闭',
				handler:function(){diag.dialog("destroy");}
			}],onClose: function () {
                $(this).dialog('destroy');//销毁
            }
		});
		$addDialog.dialog('open');
		
	}
	
	function operateFormatter(value, row, index) {
		debugger;
        var htmlstr = '<button class="layui-btn layui-btn-xs" onclick="openEditDiag(\'' + row.id + '\',\'' + row.userid + '\')">编辑</button>';
        htmlstr += '<button class="layui-btn layui-btn-xs layui-btn-danger" onclick="deleteRow(\'' + row.id + '\')">删除</button>';
        //htmlstr += '<button class="layui-btn layui-btn-xs" onclick="openChkinputitemDiag(\'' + row.id + '\')">输入项维护</button>';
        htmlstr += '<button class="layui-btn layui-btn-xs" onclick="openChkinputitemDiag(\'' + row.id + '\',\''+row.chkpointname+'\')">输入项维护</button>';
        return htmlstr;
    }
	
	function deleteRow(id){
		debugger;
		$.messager.confirm("操作提示", "删除巡查点将会删除与之关联的一切信息！是否删除？", function (data) {
			if(data) {
				$.post("/chkpoint/delChkpoint",{"chkpointid":id},function(res,status){
					 if (status == 'success') { // 后台返回状态值
		                 $.iMessager.show({title: '我的消息', msg: res.message, timeout: 5000, showType: 'slide'});// '消息窗口'组件
		                 $("#chkpointDg").iDatagrid('reload');// 刷新下表格数据（chkpointDg是上面数据表格的id）
		                 //$('#chkpointAddDialog').iDialog('destroy');// 销毁dialog面板
		             } else {
		                 $.iMessager.show({title: '我的消息', msg: res.message, timeout: 5000, showType: 'slide'});// '消息窗口'组件
		             }
				},'JSON');
			}else {}
		});
	}
	
	//打开编辑页面
	var ID = "";//定义全局变量用于保存当前巡查点id
	var USERID = "";//定义全局变量用于修改页回显责任人
	function openEditDiag(id,userid){
		debugger;
		ID = id;
		USERID = userid;
		$.ajax({ url: "/chkpoint/queryChkpointById?chkpointid="+ID, 
 			type:"get",dataType:"json", success: function(data){
 			openDialog(data.data);//调用下面的用于回显的打开对话框函数
		 }}); //调用下面的函数时只提供了返回的chkpoint对象，并没有authids的数组，这个怎么处理呢？？？
	}
	
	//由openEditDiag(id)函数末尾调用
	function openDialog(d){
		debugger;
		var $updateDialog = $('<form id="chkpointDg-update"  style="width: 900px; height: 500px; margin: auto; display: none;"></form>');
		var diag = $updateDialog.dialog({
		    title: '巡查点编辑',
		    href: '/web/view/chk/chkpoint_add.html',
		    modal: true,
		    resizable:true,
 		    maximizable:true,
		    collapsible:true,
		    buttons:[{
				text:'保存',
				handler:function(){
					if($('#chkpointDg-update').form('validate')) {
						  var formData = $("#chkpointDg-update").serialize();
						  var url = '/chkpoint/updateChkpoint';
			            	$.post(url,formData+'&chkpointid='+ID,function (res,status) {
				                if (status == 'success') { // 后台返回状态值
				                    $.iMessager.show({title: '我的消息', msg: res.message, timeout: 5000, showType: 'slide'});// '消息窗口'组件
				                    $("#chkpointDg").iDatagrid('reload');// 刷新下表格数据
				                    diag.dialog("destroy");// 销毁dialog面板
				                } else {
				                    $.iMessager.show({title: '我的消息', msg: res.message, timeout: 5000, showType: 'slide'});// '消息窗口'组件
				                }
				            },'JSON');
					  }
				}
			},{
				text:'关闭',
				handler:function(){diag.dialog("destroy");}
			}],
			onClose: function () {
                $(this).dialog('destroy');//销毁
            },onLoad :function(){
        		debugger;
            	$('#chkpointDg-update').form('load',d);//回显数据
            }
		});
		$updateDialog.dialog('open');
	}
	
	//录入项维护界面（还需要修改部分定义与参数）
	function openChkinputitemDiag(chkpointid,chkpointname){
		//alert(chkpointid+"最大化打开录入项维护dialog界面，界面中套chkinputitem_add.html页面");
		ID = chkpointid;//重新给全局变量赋值
		debugger;
		var $chkinputitemDialog = $('<form id="chkinputitemDg-add"  style="margin: auto; display: none;"></form>');
		var diag = $chkinputitemDialog.dialog({
		    title: '巡查点：'+chkpointname+'   录入项维护',
		    href: '/web/view/chk/chkinputitem.html',
		    modal: false,
 		    maximizable:true,
		    collapsible:true,
		    maxmin: true,
		    fit:true,
			onClose: function () {
                		$(this).dialog('destroy');//销毁
            		 },
            onLoad :function(){
						//alert("页面加载完毕");
            		 }
		});
		$chkinputitemDialog.dialog('open');
		//fit属性继承自panel的属性，当值为true时，自动填满父容器；
	}
</script>


</body>
</html>